package com.example.chasshelper.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.chasshelper.ClassroomStuActivity;
import com.example.chasshelper.ClassroomTeaActivity;
import com.example.chasshelper.R;
import com.example.chasshelper.dao.ClassroomDao;
import com.example.chasshelper.dao.CourseDao;
import com.example.chasshelper.dao.MessageDao;
import com.example.chasshelper.dao.RegistrationDao;
import com.example.chasshelper.dao.SolutionDao;
import com.example.chasshelper.dao.StudentDao;
import com.example.chasshelper.dao.TeacherDao;
import com.example.chasshelper.dao.TestDao;
import com.example.chasshelper.model.Classroom;
import com.example.chasshelper.model.Student;
import com.example.chasshelper.model.Teacher;
import com.example.chasshelper.utils.DaoUtils;

import java.util.List;
/*
* 数据从ClassroomTeaFragment传送过来
* 数据传送到ClassroomTeaActivity
* */
public class ClassroomTeaAdapter extends RecyclerView.Adapter<ClassroomTeaAdapter.ClassroomTeaViewHolder>{
    private Context mContext;
    //数据
    private List<Classroom> list;
    private Teacher teacher;
    //dao
    private TeacherDao teacherDao= DaoUtils.getTeacherDao();
    private StudentDao studentDao=DaoUtils.getStudentDao();
    private CourseDao courseDao=DaoUtils.getCourseDao();
    private ClassroomDao classroomDao=DaoUtils.getClassroomDao();
    private RegistrationDao registrationDao=DaoUtils.getRegistrationDao();
    private SolutionDao solutionDao = DaoUtils.getSolutionDao();
    private MessageDao messageDao = DaoUtils.getMessageDao();
    private TestDao testDao = DaoUtils.getTestDao();

    private int mPosition;
    public int getmPosition() {
        return mPosition;
    }

    //接收数据
    public ClassroomTeaAdapter(Context mContext, List<Classroom> list, Teacher teacher) {
        this.mContext = mContext;
        this.list = list;
        this.teacher = teacher;
    }

    //接收数据

    public void setList(List<Classroom> list) {
        this.list = list;
    }
    /*
     * 绑定布局
     * */
    @NonNull
    @Override
    public ClassroomTeaViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        ClassroomTeaAdapter.ClassroomTeaViewHolder classroomTeaViewHolder = new ClassroomTeaAdapter.ClassroomTeaViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_classroom_rv_tea, parent, false));
        return classroomTeaViewHolder;
    }

    /*
     * 设置每一个item
     * */
    @Override
    public void onBindViewHolder(@NonNull ClassroomTeaViewHolder holder, int position) {
        //回显
        Classroom classroom = list.get(position);
        holder.tv_id.setText("课堂id:"+String.valueOf(classroom.getClassroomId()));
        holder.tv_name.setText("课堂名:"+classroom.getClassroomName());
        holder.tv_time.setText("创建时间:"+classroom.getClassroomTime());
        //点击事件
        holder.ll_oneClassroom.setOnClickListener(new View.OnClickListener() {//进入课堂，并传递数据
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.putExtra("classroom",classroom);
                intent.putExtra("teacher", teacher);
                intent.setClass(mContext, ClassroomTeaActivity.class);
                mContext.startActivity(intent);
            }
        });

    }

    /*
     * 返回item数量
     * */
    @Override
    public int getItemCount() {
        return list.size();
    }

    /*
     * item布局
     * */
    class ClassroomTeaViewHolder extends RecyclerView.ViewHolder{
        //控件
        LinearLayout ll_oneClassroom;
        TextView tv_id;
        TextView tv_name;
        TextView tv_time;
        public ClassroomTeaViewHolder(@NonNull View itemView) {
            super(itemView);
            //绑定控件
            ll_oneClassroom = itemView.findViewById(R.id.ll_oneClassroom);
            tv_id = itemView.findViewById(R.id.tv_id);
            tv_name = itemView.findViewById(R.id.tv_name);
            tv_time = itemView.findViewById(R.id.tv_time);
            itemView.setLongClickable(true);
        }
    }

}
